{extend name="./base" /}

{block name="body"}
<form class="layui-form model-form" id="thisForm">
	<div class="layui-form-item">
		<label class="layui-form-label">所属角色</label>
		<div class="layui-input-inline">
			<select name="form[groupid]">
				<option>--请选择--</option>
				{if !empty($roles)}
					{foreach $roles as $gid => $gname}
						<option value="{$gid}" {if $data && $gid == $data['group_id']}selected{/if}>{$gname}</option>
					{/foreach}
				{/if}
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否超级管理员</label>
		<div class="layui-input-block">
			<input type="radio" name="form[is_admin]" value="1" title="是" {if !empty($data) && $data['is_admin'] == 1}checked{/if}>
			<input type="radio" name="form[is_admin]" value="2" title="否" {if !empty($data) && $data['is_admin'] != 1}checked{/if}>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">账号</label>
		<div class="layui-input-block">
			<input name="form[username]" class="layui-input" lay-verify="required" value="{$data['username'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">密码</label>
		<div class="layui-input-block">
			<input name="form[password]" class="layui-input" placeholder="为空则不修改" />
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">昵称</label>
		<div class="layui-input-block">
			<input name="form[nickname]" class="layui-input" lay-verify="required" value="{$data['nickname'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden" name="form[id]" value="{$data['id'] ?? 0}">
			<button class="layui-btn" lay-filter="formSubmit" lay-submit>保存</button>
			<button class="layui-btn layui-btn-primary" type="reset" >重置</button>
		</div>
	</div>
</form>
{/block}

{block name="script"}
<script>
	layui.use(['layer', 'form', 'table'], function () {
		var $ = layui.jquery, form= layui.form;

		// 表单提交
		form.on('submit(formSubmit)', function (data) {
			let formData = data.field;
			$.post('/admin/rbac/editadmin', formData, function(res){
				if (res.code != 0) {
					layer.msg(res.msg, {icon:2, time: 1000}, function(){
						window.location.href = '/admin/rbac/admin';
					})
				} else {
					window.location.href = '/admin/rbac/admin';
				}
			})
			return false;
		});
	})
</script>
{/block}